LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-09-2007, 12:44 PM   #1
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 50
[PHP] Put code in a seperate file


I have a page with a div-tag.
[html]
<html>
<head>
<title>My Page</title>
</head>

<body>
The cow says:
<div id="mydiv"></div>
</body>
</html>
[/html]

I want to put some Javascript or PHP code inside there to put the content of the following file into the div called "mydiv":
PHP Code:
<b>
<?
echo "Moo";
?>
</b>

Last edited by Ephracis; 10-09-2007 at 12:59 PM.
 
Old 10-09-2007, 12:55 PM   #2
lucazorzi
Member
 
Registered: Jul 2006
Location: Italy
Distribution: Ubuntu 11.04, Debian, OS X
Posts: 71

Rep: Reputation: 16
Can't you use
PHP Code:
include('path/to/file.php'); 
?
 
Old 10-09-2007, 12:58 PM   #3
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
Quote:
Originally Posted by lucazorzi View Post
Can't you use
PHP Code:
include('path/to/file.php'); 
?
How will that put the content of path/to/file.php inside that div?
 
Old 10-09-2007, 01:19 PM   #4
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
Code:
<html>
<head>
<title>My Page</title>
</head>

<body>
The cow says:
<div id="mydiv"><?php include('somefile.php'); ?></div>
</body>
</html>
Something like that? Not checked for correct syntax and it's a while ago that I touched php from scratch.
 
Old 10-09-2007, 01:40 PM   #5
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
Quote:
Originally Posted by Wim Sturkenboom View Post
Code:
<html>
<head>
<title>My Page</title>
</head>

<body>
The cow says:
<div id="mydiv"><?php include('somefile.php'); ?></div>
</body>
</html>
Something like that? Not checked for correct syntax and it's a while ago that I touched php from scratch.
Cool, I have only been using include in the header before. Anyway it worked perfectly. I was able to put only HTML-code inside the php-file and use PHP to include it.

But I wish there was a way to use Javascript to change the content to be read from another file containing HTML/PHP.

Last edited by Ephracis; 10-09-2007 at 01:48 PM.
 
Old 10-09-2007, 02:57 PM   #6
nc3b
Member
 
Registered: Aug 2005
Posts: 330

Rep: Reputation: 32
Quote:
But I wish there was a way to use Javascript to change the content to be read from another file containing HTML/PHP.
If you haven't done that already, take a look at "AJAX" . It may suit your needs. Cheers
 
Old 10-09-2007, 04:10 PM   #7
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
Quote:
Originally Posted by nc3b View Post
If you haven't done that already, take a look at "AJAX" . It may suit your needs. Cheers
I have done that but it is too complex. All tutorials and other stuff I find on the net contains of frameworks and a vast number of documents I need to read. I just do not know where to start. :/
 
Old 10-10-2007, 01:06 PM   #8
nc3b
Member
 
Registered: Aug 2005
Posts: 330

Rep: Reputation: 32
Start here then. The first thing you see will help you understand why I double-quoted "AJAX". Cheers
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
merge ASP code with PHP code.. possible ?? ALInux Programming 7 12-30-2005 08:40 AM
import fail to put code to the repository powah Linux - Software 0 10-25-2005 02:09 PM
where to put this code? xoros Linux - Laptop and Netbook 10 05-30-2005 08:34 PM
php projects: define each class in a seperate file? ldp Programming 4 09-16-2004 05:00 PM
How do I put root Password from code in sudo ? rhawi Programming 8 06-18-2004 12:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration